package com.hotel.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hotel.model.auto.Room;
import com.hotel.model.auto.RoomClass;
import com.hotel.model.auto.Roomtype;
import com.hotel.service.IRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author
 * @since 2023-04-03
 */
@RestController
@RequestMapping("/room")
public class RoomController {

    @Autowired
    private IRoomService iRoomService;

    /*查询房间*/
    @GetMapping("/getRoom")
    public List<RoomClass> getRoom() {
        return iRoomService.findAllRoom();
    }

    /*通过id查询房间*/
    @GetMapping("/getRoomById/{id}")
    public Room getRoomById(@PathVariable("id") int id) {
        return iRoomService.getById(id);
    }

    /*修改房间*/
    @PostMapping("/updateRoom")
    public void updateRoom(@RequestBody Room room) {
        iRoomService.updateById(room);
    }

    /*添加房间*/
    @PostMapping("/setRoom")
    public void setRoom(@RequestBody Room room) {
        System.out.println(room);
        iRoomService.save(room);
    }

    /*删除房间*/
    @PostMapping("/deletedById/{id}")
    public boolean deleted(@PathVariable("id") int id) {
        return iRoomService.removeById(id);
    }

    /*批量删除房间*/
    @PostMapping("/deletedAllById")
    public boolean deletedAllById(@RequestBody int[] delarr) {
        for (int i : delarr) {
            System.out.println(i);
            iRoomService.removeById(i);
        }
        return true;
    }

    /*模糊查询房间类型数据*/
    @PostMapping("/selectRoom/{input}")
    public List<Map<String, Object>> selectInfo(@PathVariable("input") String value) {
        System.out.println(value);
        QueryWrapper<Room> queryWrapper = new QueryWrapper<>();
        /*核心模糊算法*/
        queryWrapper.like("room_id", value);
        List<Map<String, Object>> maps = iRoomService.listMaps(queryWrapper);
        System.out.println(maps);
        return maps;
    }
}
